import { LoadingBar } from 'quasar'
import InterfaceProxy from 'src/utils/mider'
import { defaultOptions, ResponseData } from '../_options'

/**
 * 工具
 * @namespace iTop
 */

/** @lends iTop# */
const interfaceOpt = {
  create: {
    name: '新增',
    url: 'p/v1/top-api/create',
    method: 'post',
    params: {
      data: Object
    },
    beforeSend () {
      LoadingBar.start()
    },
    successHandler (res: ResponseData) {
      LoadingBar.stop()
      return {
        success: res.code === 0,
        data: res.data,
        top: res.msg,
        msg: res.msg
      }
    }
  },
  update: {
    name: '保存/更新内容',
    url: 'p/v1/top-api/update',
    method: 'post',
    params: {
      data: Object
    }
  },
  delete: {
    name: '删除内容',
    url: 'p/v1/top-api/delete',
    method: 'post',
    params: {
      data: Object
    }
  },
  pause: {
    name: '停用通道',
    url: 'p/v1/top-api/pause',
    method: 'post',
    params: {
      data: Object
    }
  },
  getListPub: {
    url: '/p/v1/top-api/list/pub',
    method: 'get'
  },
  getListUser: {
    url: '/p/v1/top-api/list/user',
    method: 'get'
  }
}

/** @mixes iTop */
const iTop = new InterfaceProxy(interfaceOpt, [defaultOptions])
export default iTop
